package com.java1412;

import com.java1412.servlet.UserServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;

/**
 * @author java1412
 * @create 2021-05-20 9:40
 */
@SpringBootApplication
@ServletComponentScan(basePackages = {"com.java1412.servlet"})
public class SpringBootDemo20Application {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootDemo20Application.class, args);
    }

    /**
     * ServletRegistrationBean:注册创建的Servlet类
     *
     * @return
     */
    @Bean
    public ServletRegistrationBean getServletRegistrationBean() {
        ServletRegistrationBean<UserServlet> bean = new ServletRegistrationBean<>(new UserServlet());
        // url映射路径
        bean.addUrlMappings("/user");
        return bean;
    }
}
